using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSEINK
    {
        public DataRow Convert2FSEINK(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFSEINK(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FEMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FEART"] = " ".PadRight(20 ); 
         dwReturn["FEVAR"] = " ".PadRight(2 ); 
         dwReturn["FEFARBE"] = " ".PadRight(10 ); 
         dwReturn["FEGROE"] = " ".PadRight(7 ); 
         dwReturn["FEAUFM"] = " ".PadRight(2 ); 
         dwReturn["FEVERP"] = " ".PadRight(3 ); 
         dwReturn["FELIEFNR"] = " ".PadRight(8 ); 
         dwReturn["FEAENZL"] = " ".PadRight(0 ); 
         dwReturn["FEAENB"] = " ".PadRight(8 ); 
         dwReturn["FEAEND"] = " ".PadRight(0 ); 
         dwReturn["FENEUB"] = " ".PadRight(8 ); 
         dwReturn["FENEUD"] = " ".PadRight(0 ); 
         dwReturn["FEHARBEZ"] = " ".PadRight(40 ); 
         dwReturn["FEHFBBEZ"] = " ".PadRight(30 ); 
         dwReturn["FEEANL"] = " ".PadRight(2 ); 
         dwReturn["FEEANF"] = " ".PadRight(5 ); 
         dwReturn["FEEANA"] = " ".PadRight(5 ); 
         dwReturn["FEEANP"] = " ".PadRight(1 ); 
         dwReturn["FEMWSTGR"] = " ".PadRight(2 ); 
         dwReturn["FEUEBERL"] = " ".PadRight(0 ); 
         dwReturn["FEUNTERL"] = " ".PadRight(0 ); 
         dwReturn["FELIEFZT"] = " ".PadRight(3 ); 
         dwReturn["FEMINBSLM1"] = " ".PadRight(0 ); 
         dwReturn["FEVPEINH1"] = " ".PadRight(3 ); 
         dwReturn["FEANZVP1"] = " ".PadRight(0 ); 
         dwReturn["FEPREIS1"] = " ".PadRight(0 ); 
         dwReturn["FEPRDAT1"] = " ".PadRight(0 ); 
         dwReturn["FEMINBSLM2"] = " ".PadRight(0 ); 
         dwReturn["FEVPEINH2"] = " ".PadRight(3 ); 
         dwReturn["FEANZVP2"] = " ".PadRight(0 ); 
         dwReturn["FEPREIS2"] = " ".PadRight(0 ); 
         dwReturn["FEPRDAT2"] = " ".PadRight(0 ); 
         dwReturn["FEMINBSLM3"] = " ".PadRight(0 ); 
         dwReturn["FEVPEINH3"] = " ".PadRight(3 ); 
         dwReturn["FEANZVP3"] = " ".PadRight(0 ); 
         dwReturn["FEPREIS3"] = " ".PadRight(0 ); 
         dwReturn["FEPRDAT3"] = " ".PadRight(0 ); 
         dwReturn["FEMINBSLM4"] = " ".PadRight(0 ); 
         dwReturn["FEVPEINH4"] = " ".PadRight(3 ); 
         dwReturn["FEANZVP4"] = " ".PadRight(0 ); 
         dwReturn["FEPREIS4"] = " ".PadRight(0 ); 
         dwReturn["FEPRDAT4"] = " ".PadRight(0 ); 
         dwReturn["FEMINBSLM5"] = " ".PadRight(0 ); 
         dwReturn["FEVPEINH5"] = " ".PadRight(3 ); 
         dwReturn["FEANZVP5"] = " ".PadRight(0 ); 
         dwReturn["FEPREIS5"] = " ".PadRight(0 ); 
         dwReturn["FEPRDAT5"] = " ".PadRight(0 ); 
         dwReturn["FEMUNR"] = " ".PadRight(15 ); 
         dwReturn["FESTAKZ"] = " ".PadRight(1 ); 
         dwReturn["FEPRIO"] = " ".PadRight(2 ); 
         dwReturn["FELART"] = " ".PadRight(20 ); 
         dwReturn["FELVAR"] = " ".PadRight(2 ); 
         dwReturn["FELFARBE"] = " ".PadRight(10 ); 
         dwReturn["FELGROE"] = " ".PadRight(7 ); 
         dwReturn["FELAUFM"] = " ".PadRight(2 ); 
         dwReturn["FELVERP"] = " ".PadRight(3 ); 
         dwReturn["FEPRGRP"] = " ".PadRight(1 ); 
         dwReturn["FEURLAND"] = " ".PadRight(3 ); 
         dwReturn["FEFILLER"] = " ".PadRight(77 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFSEINK(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFSEINK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFSEINK(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFSEINK(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFSEINK(dwLocal, ITXDBVERSION);
            }
            UpdateFSEINK(dwLocal);
        }
        public void InsertFSEINK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FSEINK(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFSEINK(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSEINK WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FSEINK  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FSEINK";
            Return = Result;
            return Return;
        }
        public void DeleteFSEINK(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FSEINK   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFSEINK(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FSEINK SET "
                    +"FEMANDANT= :FEMANDANT,"
                    +"FEART= :FEART,"
                    +"FEVAR= :FEVAR,"
                    +"FEFARBE= :FEFARBE,"
                    +"FEGROE= :FEGROE,"
                    +"FEAUFM= :FEAUFM,"
                    +"FEVERP= :FEVERP,"
                    +"FELIEFNR= :FELIEFNR,"
                    +"FEAENZL= :FEAENZL,"
                    +"FEAENB= :FEAENB,"
                    +"FEAEND= :FEAEND,"
                    +"FENEUB= :FENEUB,"
                    +"FENEUD= :FENEUD,"
                    +"FEHARBEZ= :FEHARBEZ,"
                    +"FEHFBBEZ= :FEHFBBEZ,"
                    +"FEEANL= :FEEANL,"
                    +"FEEANF= :FEEANF,"
                    +"FEEANA= :FEEANA,"
                    +"FEEANP= :FEEANP,"
                    +"FEMWSTGR= :FEMWSTGR,"
                    +"FEUEBERL= :FEUEBERL,"
                    +"FEUNTERL= :FEUNTERL,"
                    +"FELIEFZT= :FELIEFZT,"
                    +"FEMINBSLM1= :FEMINBSLM1,"
                    +"FEVPEINH1= :FEVPEINH1,"
                    +"FEANZVP1= :FEANZVP1,"
                    +"FEPREIS1= :FEPREIS1,"
                    +"FEPRDAT1= :FEPRDAT1,"
                    +"FEMINBSLM2= :FEMINBSLM2,"
                    +"FEVPEINH2= :FEVPEINH2,"
                    +"FEANZVP2= :FEANZVP2,"
                    +"FEPREIS2= :FEPREIS2,"
                    +"FEPRDAT2= :FEPRDAT2,"
                    +"FEMINBSLM3= :FEMINBSLM3,"
                    +"FEVPEINH3= :FEVPEINH3,"
                    +"FEANZVP3= :FEANZVP3,"
                    +"FEPREIS3= :FEPREIS3,"
                    +"FEPRDAT3= :FEPRDAT3,"
                    +"FEMINBSLM4= :FEMINBSLM4,"
                    +"FEVPEINH4= :FEVPEINH4,"
                    +"FEANZVP4= :FEANZVP4,"
                    +"FEPREIS4= :FEPREIS4,"
                    +"FEPRDAT4= :FEPRDAT4,"
                    +"FEMINBSLM5= :FEMINBSLM5,"
                    +"FEVPEINH5= :FEVPEINH5,"
                    +"FEANZVP5= :FEANZVP5,"
                    +"FEPREIS5= :FEPREIS5,"
                    +"FEPRDAT5= :FEPRDAT5,"
                    +"FEMUNR= :FEMUNR,"
                    +"FESTAKZ= :FESTAKZ,"
                    +"FEPRIO= :FEPRIO,"
                    +"FELART= :FELART,"
                    +"FELVAR= :FELVAR,"
                    +"FELFARBE= :FELFARBE,"
                    +"FELGROE= :FELGROE,"
                    +"FELAUFM= :FELAUFM,"
                    +"FELVERP= :FELVERP,"
                    +"FEPRGRP= :FEPRGRP,"
                    +"FEURLAND= :FEURLAND,"
                    +"FEFILLER= :FEFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FEMANDANT", OracleType.NVarChar).Value = dwData["FEMANDANT"].ToString(); 
          or1.Parameters.Add("FEART", OracleType.NVarChar).Value = dwData["FEART"].ToString(); 
          or1.Parameters.Add("FEVAR", OracleType.NVarChar).Value = dwData["FEVAR"].ToString(); 
          or1.Parameters.Add("FEFARBE", OracleType.NVarChar).Value = dwData["FEFARBE"].ToString(); 
          or1.Parameters.Add("FEGROE", OracleType.NVarChar).Value = dwData["FEGROE"].ToString(); 
          or1.Parameters.Add("FEAUFM", OracleType.NVarChar).Value = dwData["FEAUFM"].ToString(); 
          or1.Parameters.Add("FEVERP", OracleType.NVarChar).Value = dwData["FEVERP"].ToString(); 
          or1.Parameters.Add("FELIEFNR", OracleType.NVarChar).Value = dwData["FELIEFNR"].ToString(); 
          or1.Parameters.Add("FEAENZL", OracleType.NVarChar).Value = dwData["FEAENZL"].ToString(); 
          or1.Parameters.Add("FEAENB", OracleType.NVarChar).Value = dwData["FEAENB"].ToString(); 
          or1.Parameters.Add("FEAEND", OracleType.NVarChar).Value = dwData["FEAEND"].ToString(); 
          or1.Parameters.Add("FENEUB", OracleType.NVarChar).Value = dwData["FENEUB"].ToString(); 
          or1.Parameters.Add("FENEUD", OracleType.NVarChar).Value = dwData["FENEUD"].ToString(); 
          or1.Parameters.Add("FEHARBEZ", OracleType.NVarChar).Value = dwData["FEHARBEZ"].ToString(); 
          or1.Parameters.Add("FEHFBBEZ", OracleType.NVarChar).Value = dwData["FEHFBBEZ"].ToString(); 
          or1.Parameters.Add("FEEANL", OracleType.NVarChar).Value = dwData["FEEANL"].ToString(); 
          or1.Parameters.Add("FEEANF", OracleType.NVarChar).Value = dwData["FEEANF"].ToString(); 
          or1.Parameters.Add("FEEANA", OracleType.NVarChar).Value = dwData["FEEANA"].ToString(); 
          or1.Parameters.Add("FEEANP", OracleType.NVarChar).Value = dwData["FEEANP"].ToString(); 
          or1.Parameters.Add("FEMWSTGR", OracleType.NVarChar).Value = dwData["FEMWSTGR"].ToString(); 
          or1.Parameters.Add("FEUEBERL", OracleType.NVarChar).Value = dwData["FEUEBERL"].ToString(); 
          or1.Parameters.Add("FEUNTERL", OracleType.NVarChar).Value = dwData["FEUNTERL"].ToString(); 
          or1.Parameters.Add("FELIEFZT", OracleType.NVarChar).Value = dwData["FELIEFZT"].ToString(); 
          or1.Parameters.Add("FEMINBSLM1", OracleType.NVarChar).Value = dwData["FEMINBSLM1"].ToString(); 
          or1.Parameters.Add("FEVPEINH1", OracleType.NVarChar).Value = dwData["FEVPEINH1"].ToString(); 
          or1.Parameters.Add("FEANZVP1", OracleType.NVarChar).Value = dwData["FEANZVP1"].ToString(); 
          or1.Parameters.Add("FEPREIS1", OracleType.NVarChar).Value = dwData["FEPREIS1"].ToString(); 
          or1.Parameters.Add("FEPRDAT1", OracleType.NVarChar).Value = dwData["FEPRDAT1"].ToString(); 
          or1.Parameters.Add("FEMINBSLM2", OracleType.NVarChar).Value = dwData["FEMINBSLM2"].ToString(); 
          or1.Parameters.Add("FEVPEINH2", OracleType.NVarChar).Value = dwData["FEVPEINH2"].ToString(); 
          or1.Parameters.Add("FEANZVP2", OracleType.NVarChar).Value = dwData["FEANZVP2"].ToString(); 
          or1.Parameters.Add("FEPREIS2", OracleType.NVarChar).Value = dwData["FEPREIS2"].ToString(); 
          or1.Parameters.Add("FEPRDAT2", OracleType.NVarChar).Value = dwData["FEPRDAT2"].ToString(); 
          or1.Parameters.Add("FEMINBSLM3", OracleType.NVarChar).Value = dwData["FEMINBSLM3"].ToString(); 
          or1.Parameters.Add("FEVPEINH3", OracleType.NVarChar).Value = dwData["FEVPEINH3"].ToString(); 
          or1.Parameters.Add("FEANZVP3", OracleType.NVarChar).Value = dwData["FEANZVP3"].ToString(); 
          or1.Parameters.Add("FEPREIS3", OracleType.NVarChar).Value = dwData["FEPREIS3"].ToString(); 
          or1.Parameters.Add("FEPRDAT3", OracleType.NVarChar).Value = dwData["FEPRDAT3"].ToString(); 
          or1.Parameters.Add("FEMINBSLM4", OracleType.NVarChar).Value = dwData["FEMINBSLM4"].ToString(); 
          or1.Parameters.Add("FEVPEINH4", OracleType.NVarChar).Value = dwData["FEVPEINH4"].ToString(); 
          or1.Parameters.Add("FEANZVP4", OracleType.NVarChar).Value = dwData["FEANZVP4"].ToString(); 
          or1.Parameters.Add("FEPREIS4", OracleType.NVarChar).Value = dwData["FEPREIS4"].ToString(); 
          or1.Parameters.Add("FEPRDAT4", OracleType.NVarChar).Value = dwData["FEPRDAT4"].ToString(); 
          or1.Parameters.Add("FEMINBSLM5", OracleType.NVarChar).Value = dwData["FEMINBSLM5"].ToString(); 
          or1.Parameters.Add("FEVPEINH5", OracleType.NVarChar).Value = dwData["FEVPEINH5"].ToString(); 
          or1.Parameters.Add("FEANZVP5", OracleType.NVarChar).Value = dwData["FEANZVP5"].ToString(); 
          or1.Parameters.Add("FEPREIS5", OracleType.NVarChar).Value = dwData["FEPREIS5"].ToString(); 
          or1.Parameters.Add("FEPRDAT5", OracleType.NVarChar).Value = dwData["FEPRDAT5"].ToString(); 
          or1.Parameters.Add("FEMUNR", OracleType.NVarChar).Value = dwData["FEMUNR"].ToString(); 
          or1.Parameters.Add("FESTAKZ", OracleType.NVarChar).Value = dwData["FESTAKZ"].ToString(); 
          or1.Parameters.Add("FEPRIO", OracleType.NVarChar).Value = dwData["FEPRIO"].ToString(); 
          or1.Parameters.Add("FELART", OracleType.NVarChar).Value = dwData["FELART"].ToString(); 
          or1.Parameters.Add("FELVAR", OracleType.NVarChar).Value = dwData["FELVAR"].ToString(); 
          or1.Parameters.Add("FELFARBE", OracleType.NVarChar).Value = dwData["FELFARBE"].ToString(); 
          or1.Parameters.Add("FELGROE", OracleType.NVarChar).Value = dwData["FELGROE"].ToString(); 
          or1.Parameters.Add("FELAUFM", OracleType.NVarChar).Value = dwData["FELAUFM"].ToString(); 
          or1.Parameters.Add("FELVERP", OracleType.NVarChar).Value = dwData["FELVERP"].ToString(); 
          or1.Parameters.Add("FEPRGRP", OracleType.NVarChar).Value = dwData["FEPRGRP"].ToString(); 
          or1.Parameters.Add("FEURLAND", OracleType.NVarChar).Value = dwData["FEURLAND"].ToString(); 
          or1.Parameters.Add("FEFILLER", OracleType.NVarChar).Value = dwData["FEFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
